<fieldset id="fd1" style="width:80%;margin:5px;">
	<legend><span>员工信息查询</span></legend>
	<div class="fieldset-body">
		<table class="form-table" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<td class="form-label" style="width:80px;">组织机构:</td>
				<td style="width:150px"><input id="agency" expandOnLoad="true" class="mini-treeselect" url="/common/agencyOne" multiSelect="false" textField="name" valueField="id" parentField="parent" checkRecursive="true" showFolderCheckBox="true"/></td>
				<td class="form-label" style="width:80px;">员工编号:</td>
				<td style="width:150px"><input id="user" class="mini-textbox" emptyText="请输入账户" style="width:100%;"/></td>
				<td class="form-label" style="width:80px;">员工名称:</td>
				<td style="width:150px"><input id="name" class="mini-textbox" emptyText="请输入名称" style="width:100%;"/></td>
				<td style="width:150px"><a class="mini-button" id="search" iconCls="icon-search">查询...</a></td>
			</tr>
		</table>
	</div>
</fieldset>
<div class="mini-toolbar" style="padding:0px;margin:6px 0px 0px 0px;border-bottom:0;width:100%;">
	<table style="width:100%;">
		<tr>
			<td style="width:100%;">
				<a class="mini-button" iconCls="icon-add" id="userAdd" plain="true">增加员工</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-edit" id="userUpd" plain="true">修改员工资料</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-ok" id="userStart" plain="true">启用</a>
				<a class="mini-button" iconCls="icon-lock" id="userEnd" plain="true">禁用</a>
                <a class="mini-button" iconCls="icon-remove" id="userDel" plain="true">删除</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-filter" id="buttonReload" plain="true">重置密码(密码：888888)</a>
			</td>
		</tr>
	</table>
</div>
<div id="grid1" class="mini-datagrid" idField="id" pageSize="20" style="width:100%;height:80%;" url="/staff/staffList" >
	<div property="columns">
		<div type="indexcolumn" headerAlign="center">编号</div>
        <div field="agency" width="100" allowSort="true">部门机构</div>
        <div field="users" width="100">员工编号</div>
		<div field="name" width="100">真实姓名</div>
		<div field="stopname" headerAlign="center" align="center" width="60">状态</div>
		<div field="position" width="80" allowSort="true">职位 </div>
		<div field="sex" width="40" allowSort="true">性别</div>
		<div field="mobile_phone" width="100">手机</div>
		<div field="tel" width="100" allowSort="true">座机</div>
		<div field="email" width="100">邮箱</div>
		<div field="remark" width="200">备注</div>
		<div field="updated" width="80" dateFormat="yyyy-MM-dd" allowSort="true">更新日期</div>
    </div>
</div>
<iframe id="exportIFrame" style="display:none;"></iframe>
<script type="text/javascript">
mini.parse();
var urlDel = "/basic/deviceDel";
var urlUpd = "/basic/deviceUpd";
var grid = mini.get("grid1");
grid.load();

//设置行样式
grid.on("drawcell", function (e) {
	if(e.column.field == "stopname"){
		if(e.value=="停用"){
			e.cellStyle = "color:red;";
		}else{
			e.cellStyle = "color:#006600;";
		}
	}
});

//检索
$("#search").click(function(){
	grid.load({agency:mini.get("agency").getValue(),user:mini.get("user").getValue(),name:mini.get("name").getValue()});
});

//禁用
$("#userEnd").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要禁用这个员工吗？",function(){
			$.post('/staff/userEnd',{sid:row.sid,cid:row.cid},function(data){
				if(data.code=='OK'){
					grid.load({agency:mini.get("agency").getValue(),user:mini.get("user").getValue(),name:mini.get("name").getValue()});
				}else{
					parent.$.dooDialog.alert('员工禁用失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

//启用
$("#userStart").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要启用这个员工吗？",function(){
			$.post('/staff/userStart',{sid:row.sid,cid:row.cid},function(data){
				if(data.code=='OK'){
					grid.load({agency:mini.get("agency").getValue(),user:mini.get("user").getValue(),name:mini.get("name").getValue()});
				}else{
					parent.$.dooDialog.alert('员工启用失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});


//启用
$("#userDel").click(function(){
    var row = grid.getSelected();
    if (row != null) {
        parent.$.dooDialog.confirm("你确定要删除这个员工吗？",function(){
            $.post('/staff/userDel',{sid:row.sid,cid:row.cid},function(data){
                if(data.code=='OK'){
                    grid.load({agency:mini.get("agency").getValue(),user:mini.get("user").getValue(),name:mini.get("name").getValue()});
                }else{
                    parent.$.dooDialog.alert('员工删除失败！');
                    return false;
                }
            },'json');
        });
    } else {
        parent.$.dooDialog.alert("请选中一条记录");
    }
});

//派工到下属组织机构
$("#userAdd").click(function(){
	mini.open({
		url: "/staff/useraddedit",
		title: "增加员工", width: 700,height:430,
		onload: function(){
			var iframe = this.getIFrameEl();
			var data = { action: "add"};
			iframe.contentWindow.SetData(data);
		},
		ondestroy:function(action){
			grid.load({agency:mini.get("agency").getValue(),user:mini.get("user").getValue(),name:mini.get("name").getValue()});
		}
	});
	$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
});

//派工到下属组织机构
$("#userUpd").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/staff/useraddedit?sid=" + row.sid,
            title: "增加员工", width: 700,height:430,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = { action: "edit",
                             cid:row.cid,
                             sid:row.sid,
                             user:row.users,
                             name:row.name,
                             agency:row.agency_id,
                             position_id:row.position_id,
                             position:row.position,
                             sex:row.sex,
                             mobile_phone:row.mobile_phone,
                             tel:row.tel,
                             email:row.email,
                             remark:row.remark
                           };
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	grid.load({agency:mini.get("agency").getValue(),user:mini.get("user").getValue(),name:mini.get("name").getValue()});
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

//充值密码
$("#buttonReload").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要重置这个顾客的密码吗？",function(){
			$.post('/customer/pwdReload',{id:row.sid},function(data){
				if(data.code=='OK'){
					grid.load({types:1,user:mini.get("user").getValue(),name:mini.get("name").getValue()});
					parent.$.dooDialog.alert('密码重置成功！');
				}else{
					parent.$.dooDialog.alert('密码重置失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});
</script>